const fs = require('fs')
const path = require('path')

module.exports = ( cities ) => {

  let shopWrappers = [];

  if( cities && cities.length > 0){
    
    for (const city of cities) {
      let p = path.join(process.cwd(), 'cities1', `${city.name}.json`);
      if(fs.existsSync(p)){
        let data = require(p);
        if(data.shopBeans && data.shopBeans.length > 0){
          shopWrappers.push(...data.shopBeans )
          for (let shop of shopWrappers) {
            shop.cityName = city.name;
            shop.shopUrl = `http://www.dianping.com/shop/${shop.shopId}`;
          }

        } 
      }
    }  
  }

  return shopWrappers;
}






